package cn.com.io.day20151214.control;

import cn.com.io.day20151214.pojo.Person;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * 对象反序列化
 */
public class ReadObject {
    public static void main(String[] args) throws IOException {
        ObjectInputStream ois = null;
        try {
            ois = new ObjectInputStream(new FileInputStream("Object.txt"));//创建一个ObjectInputStream输入流
            Person person = (Person) ois.readObject();//从输入流当中取出一个Java对象，并将其强制类型转换为Person类
            System.out.println("名字为："+person.getName()+"\n年龄为："+person.getAge());
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (ois != null){
                ois.close();
            }
        }
    }
}
